const app = getApp()
import { getOrderList, postSupplierDeleteOrder } from '../../../../api/index'
import { formatTimeTwo } from '../../../../utils/util'

Page({
  data: {
    orderId: '',
    detail: {},
    showDeliveryPop: false
  },
  async delOrder () {
    try {
      if (this.locking) return
      const { confirm } = await wx.$pro.showModal({ title: '确定要删除该订单吗？' })
      this.locking = true
      if (confirm) {
        await postSupplierDeleteOrder({ orderId: this.data.detail.orderId, status: this.data.detail.status })
        wx.showToast({ title: '删除成功！', icon: 'none' })
        wx.$nav.navigateBack()
      }
      this.locking = false
    } catch (err) {
      this.locking = false
      wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
    }
  },
  delivery () {
    this.setData({ showDeliveryPop: true })
  },
  close () {
    this.setData({ showDeliveryPop: false })
  },
  confirm () {
    this.setData({ showDeliveryPop: false })
    this.getDetail()
  },
  async getDetail () {
    try {
      const { ResultSet } = await getOrderList({ orderId: this.data.orderId, currentPage: 1, pageLines: 15 })
      this.setData({ detail: ResultSet.userData.orderList[0] })
    } catch (err) {
      wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
    }
  },
  onLoad ({ id }) {
    this.setData({ orderId: id })
    this.getDetail()
  }
})